<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--#include file="DataLoad.asp"-->
<%Call CheckAdmin2()%>

<html>
<head>
<title><%=GuildName%> - DKP系统</title>
<script language="JavaScript" src="inc/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Generator" content="EditPlus">
<meta name="Author" content="SULei">
<meta name="Keywords" content="DKP WOW GUILD">
<meta name="Description" content="">
<link href="<%=StylePath%>/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="<%=StylePath%>/styleplus.js"></script>

</head>

<body>
<div class="header">
<!--#include file="menu.asp"-->
</div>
<div class="main">

<%
Select Case Request("Action")
	Case "Form" '显示表单
		Call ImportForm()
	Case "RexPost"

		Dim Rex, Rex2, Rex3, Match, Matches , xmlRaidTrack
		Dim ArrPlayer, ArrJoin, ArrLeave, ArrBosskill, ArrLoot, strPlayerList
		Dim timeStart, timeEnd, strRaidTitle, strRaidnote
		Dim errtext
		Dim RaidID

		Call Initialize(Request.Form("xmltext"))
		If errtext <> "" Then
			Response.write "<div class='message'><h3>数据不完整,程序停止分析</h3>"&errtext&"</div>"
		Else
			Call RaidCreative(timeStart,timeEnd,strRaidTitle,strRaidnote)

			Call dbRenewPlayers(arrPlayer)

			Call dbAddRaidPlayer(strPlayerList)

			Call fixEvents(ArrJoin)
			Call fixEvents(ArrLeave)
			Call fixOfflineEvents(ArrJoin,ArrLeave)

			Call processJoinEvents(ArrJoin)
			Call processLeaveEvents(ArrLeave)
			Call processBosskillsEvents(ArrBosskill)
			Call processLootEvents(ArrLoot)
			Response.write "<div class='message'><h3>全部完成</h3><div><a href='raid_report.asp?id="&RaidID&"' class='abtn'>查看活动报告</a></div></div>"
		End If


		'初始化,xml数据提取转存进数组
		Sub Initialize(xml)
			Set Rex = New RegExp
			Set Rex2 = New RegExp
			Set Rex3 = New RegExp
			Rex.IgnoreCase = True
			Rex.Global = True
			Rex2.IgnoreCase = True
			Rex2.Global = True
			Rex3.IgnoreCase = True
			Rex3.Global = True
			
			'清理换行与空格,混乱标签修正
			Rex.Pattern = "[\n\r]"
			xmlRaidTrack = Rex.Replace(xml,"")
			xmlRaidTrack = Replace(xmlRaidTrack,"Join>","joins>")
			xmlRaidTrack = Replace(xmlRaidTrack,"Leave>","leaves>")
			xmlRaidTrack = Replace(xmlRaidTrack,"Loot>","loots>")
			xmlRaidTrack = Replace(xmlRaidTrack,"<![CDATA[","")
			xmlRaidTrack = Replace(xmlRaidTrack,"]]>","")
			
			

			Rex.Pattern = "<start>([^<]*)<\/start>.*?<end>([^<]*)<\/end>(?:<realm>[^<]*<\/realm>)?(?:<zone>([^<]*)<\/zone>)?" '取得起始,结束时间和 地区名(如果有)
			Rex2.Pattern = "<note>([^<]*?)<\/note><joins>" '取得备注(如果有)
			If Rex.test(xmlRaidTrack) Then
				Set Matches1 = Rex.Execute(xmlRaidTrack)
				timeStart = cov2Time(Matches1(0).SubMatches(0))
				timeEnd = cov2Time(Matches1(0).SubMatches(1))
				strRaidTitle = Matches1(0).SubMatches(2)
				If Rex2.test(xmlRaidTrack) Then
					Set Matches2 = Rex2.Execute(xmlRaidTrack)
					strRaidnote = Matches2(0).SubMatches(0)
				End If
				'Response.write timeStart&" , "&timeEnd&" , "&strRaidTitle&" , "&strRaidnote&" ,<br>"
			Else
				errtext=errtext& "缺少必要的基本信息<br>"	
			End If

			'取得player数组
			Response.write "<br><br>player<br>"
			Rex.Pattern = "<playerinfos>(.*)<\/playerinfos>"
			Rex2.Pattern = "(?:<player>|<key\d{1,4}>)(.*?)(?:<\/player>|<\/key\d{1,4}>)"
			'Rex2.Pattern = "(?:<player>|<key\d{1,4}>)<name>([^<]*)<\/name><race>([^<]*)<\/race>(?:<guild>([^<]*)<\/guild>)?<sex>([^<]*)<\/sex><class>([^<]*)<\/class>(?:<note><!\[CDATA\[(.*?)\]\]><\/note>)?<level>(\d{1,2})<\/level>(?:<\/player>|<\/key\d{1,4}>)"
			If Rex.test(xmlRaidTrack) and Rex2.test(xmlRaidTrack) Then
				Set Matches1 = Rex.Execute(xmlRaidTrack)
				Set Matches2 = Rex2.Execute(Matches1(0).SubMatches(0))
				ReDim ArrPlayer(Matches2.count,6)
				index = 0
				For Each Match in Matches2
					Rex3.Pattern = "<name>([^<]*)<\/name>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					ArrPlayer(index,0) = Matches3(0).SubMatches(0) 'name

					Rex3.Pattern = "<race>([^<]*)<\/race>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					If Rex3.test(Match.SubMatches(0)) Then ArrPlayer(index,1) = Matches3(0).SubMatches(0) '种族

					Rex3.Pattern = "<guild>([^<]*)<\/guild>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					If Rex3.test(Match.SubMatches(0)) Then ArrPlayer(index,2) = Matches3(0).SubMatches(0) '公会

					Rex3.Pattern = "<sex>([^<]*)<\/sex>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					If Rex3.test(Match.SubMatches(0)) Then ArrPlayer(index,3) = Matches3(0).SubMatches(0) '性别

					Rex3.Pattern = "<class>([^<]*)<\/class>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					If Rex3.test(Match.SubMatches(0)) Then ArrPlayer(index,4) = Matches3(0).SubMatches(0) '职业

					Rex3.Pattern = "<note>(.*?)<\/note>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					If Rex3.test(Match.SubMatches(0)) Then ArrPlayer(index,5) = Matches3(0).SubMatches(0) '注释

					Rex3.Pattern = "<level>(\d{1,2})<\/level>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					If Rex3.test(Match.SubMatches(0)) Then ArrPlayer(index,6) = Matches3(0).SubMatches(0) '等级
					'Response.write Match.SubMatches.count&ArrPlayer(index,0)&ArrPlayer(index,1)&ArrPlayer(index,2)&ArrPlayer(index,3)&ArrPlayer(index,4)&ArrPlayer(index,5)&ArrPlayer(index,6)&" ("&index&"<br>"
					index=index+1
				Next
			Else
				errtext=errtext& "未找到玩家数据<br>"	
			End If

			'取得join数组
			Response.write "<br><br>join<br>"
			Rex.Pattern = "<joins>(.*)<\/joins>"
			Rex2.Pattern = "(?:<join>|<key\d{1,4}>)<player>([^<]*)<\/player>.*?<time>([^<]*)<\/time>(?:<\/join>|<\/key\d{1,4}>)"
			If Rex.test(xmlRaidTrack) and Rex2.test(xmlRaidTrack) Then
				Set Matches1 = Rex.Execute(xmlRaidTrack)
				Set Matches2 = Rex2.Execute(Matches1(0).SubMatches(0))
				ReDim ArrJoin(Matches2.count,1)
				index = 0
				For Each Match in Matches2
				ArrJoin(index,0) = match.SubMatches(0)
				ArrJoin(index,1) = cov2time(match.SubMatches(1))
				'Response.write Match.SubMatches.count&ArrJoin(index,0)&ArrJoin(index,1)&"<br>"
				index=index+1
				Next
			Else
				Response.write "无成员中途加入<br>"
			End If

			'取得leave数组
			Response.write "<br><br>leave<br>"
			Rex.Pattern = "<leaves>(.*)<\/leaves>"
			Rex2.Pattern = "(?:<leave>|<key\d{1,4}>)<player>([^<]*)<\/player><time>([^<]*)<\/time>(?:<\/leave>|<\/key\d{1,4}>)"
			If Rex.test(xmlRaidTrack) and Rex2.test(xmlRaidTrack) Then
				Set Matches1 = Rex.Execute(xmlRaidTrack)
				Set Matches2 = Rex2.Execute(Matches1(0).SubMatches(0))
				ReDim ArrLeave(Matches2.count,1)
				index = 0
				For Each Match in Matches2
				ArrLeave(index,0) = match.SubMatches(0)
				ArrLeave(index,1) = cov2Time(match.SubMatches(1))
				'Response.write Match.SubMatches.count&ArrLeave(index,0)&ArrLeave(index,1)&"<br>"
				index=index+1
				Next
			Else
				Response.write "无成员中途离开<br>"
			End If

			'取得bosskills数组
			Response.write "<br><br>bosskills<br>"
			Rex.Pattern = "<bosskills>(.*)<\/bosskills>"
			Rex2.Pattern = "(?:<bosskill>|<key\d{1,4}>)(.*?)(?:<attendees>.*?<\/attendees>)?(?:<\/bosskill>|<\/key\d{1,4}>)"
'			Rex2.Pattern = "<bosskill><name>([^<]*)<\/name><time>([^<]*)<\/time><\/bosskill>"
			If Rex.test(xmlRaidTrack) and Rex2.test(xmlRaidTrack) Then
				Set Matches1 = Rex.Execute(xmlRaidTrack)
				Set Matches2 = Rex2.Execute(Matches1(0).SubMatches(0))
				ReDim ArrBosskill(Matches2.count,1)

				index = 0
				For Each Match in Matches2
					Rex3.Pattern = "<name>([^<]*)<\/name>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					ArrBosskill(index,0) = Matches3(0).SubMatches(0) '首领名

					Rex3.Pattern = "<time>([^<]*)<\/time>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					ArrBosskill(index,1) = cov2Time(Matches3(0).SubMatches(0)) '发生事件

				Response.write ArrBosskill(index,0)&ArrBosskill(index,1)&"<br>"
				index=index+1
				Next
			Else
				Response.write "未找到首领击杀事件<br>"
			End If
			
			'取得loot数组
			Response.write "<br><br>loot<br>"
			Rex.Pattern = "<loots>(.*)<\/loots>"
			Rex2.Pattern = "(?:<loot>|<key\d{1,4}>)(.*?)(?:<\/loot>|<\/key\d{1,4}>)"
			'Rex2.Pattern = "(?:<loot>|<key\d{1,4}>)<itemname>([^<]*)<\/itemname><itemid>(\d{4,6})[^<]*<\/itemid>(?:<icon>([^<]*)<\/icon>)?.*?(?:<color>([^<]*)<\/color>|)<count>(\d)<\/count><player>([^<]*)<\/player>(?:<costs>([^<]*)<\/costs>)?<time>([^<]*)<\/time><zone>([^<]*)<\/zone><boss>([^<]*)</boss>(?:<tooltip>([^<]*)<\/tooltip>)?<note>(-?[^-<]*)?(?: - Zone:.*? - Boss:[^\]]*?)?<\/note>(?:<\/loot>|<\/key\d{1,4}>)"
			If Rex.test(xmlRaidTrack) and Rex2.test(xmlRaidTrack) Then
				Set Matches1 = Rex.Execute(xmlRaidTrack)
				Set Matches2 = Rex2.Execute(Matches1(0).SubMatches(0))
				ReDim ArrLoot(Matches2.count,11)

				index = 0
				For Each Match in Matches2
					Rex3.Pattern = "<itemname>([^<]*)<\/itemname>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					ArrLoot(index,0) = Matches3(0).SubMatches(0) '物品名

					Rex3.Pattern = "<itemid>(\d{4,6})[^<]*<\/itemid>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					If Rex3.test(Match.SubMatches(0)) Then ArrLoot(index,1) = Matches3(0).SubMatches(0) 'int物品ID

					Rex3.Pattern = "<icon>([^<]*)<\/icon>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					If Rex3.test(Match.SubMatches(0)) Then ArrLoot(index,2) = Matches3(0).SubMatches(0) 'icon

					Rex3.Pattern = "<color>([^<]*)<\/color>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					If Rex3.test(Match.SubMatches(0)) Then ArrLoot(index,3) = Matches3(0).SubMatches(0) 'color


					Rex3.Pattern = "<count>(\d)<\/count>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					If Rex3.test(Match.SubMatches(0)) Then ArrLoot(index,4) = Matches3(0).SubMatches(0) 'int数量


					Rex3.Pattern = "<player>(.*?)<\/player>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					If Rex3.test(Match.SubMatches(0)) Then ArrLoot(index,5) = Matches3(0).SubMatches(0) '获得者


					Rex3.Pattern = "<costs>(.*?)<\/costs>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					If Rex3.test(Match.SubMatches(0)) Then ArrLoot(index,6) = Matches3(0).SubMatches(0) 'DKPcosts

					Rex3.Pattern = "<time>(.*?)<\/time>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					If Rex3.test(Match.SubMatches(0)) Then ArrLoot(index,7) = cov2Time(Matches3(0).SubMatches(0)) '时间

					Rex3.Pattern = "<zone>(.*?)<\/zone>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					If Rex3.test(Match.SubMatches(0)) Then ArrLoot(index,8) = Matches3(0).SubMatches(0) '地区

					Rex3.Pattern = "<boss>(.*?)<\/boss>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					If Rex3.test(Match.SubMatches(0)) Then ArrLoot(index,9) = Matches3(0).SubMatches(0) '掉落者

					Rex3.Pattern = "<tooltip>(.*?)<\/tooltip>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					If Rex3.test(Match.SubMatches(0)) Then ArrLoot(index,10) = Matches3(0).SubMatches(0) 'tooltip

					Rex3.Pattern = "<note>(-?[^-<]*)?(?: - Zone:.*? - Boss:[^\]]*?)?<\/note>"
					Set Matches3 = Rex3.Execute(Match.SubMatches(0))
					If Rex3.test(Match.SubMatches(0)) Then ArrLoot(index,11) = Matches3(0).SubMatches(0) '备注/DKP

					'Response.write Match.SubMatches.count&ArrPlayer(index,0)&ArrPlayer(index,1)&ArrPlayer(index,2)&ArrPlayer(index,3)&ArrPlayer(index,4)&ArrPlayer(index,5)&ArrPlayer(index,6)&" ("&index&"<br>"
					index=index+1
				Next
				
			Else
				Response.write "未找到物品拾取事件<br>"
			End If
		End Sub

		'创建/更新活动记录,获得RaidID,清空事件
		Sub RaidCreative(timeStart,timeEnd,strRaidTitle,strRaidnote)
			sql = "select * from raid where raid_concentratetime=#"&timeStart&"#"
			rs.open sql,conn,1,3
			if rs.eof or rs.bof then
				rs.close
				sql = "select * from raid where (id is null)"
				rs.open sql,conn,1,3
					rs.addnew
					rs("raid_name")=strRaidTitle&strRaidnote
					If strRaidTitle&strRaidnote ="" Then rs("raid_name")="未命名的活动"
					rs("raid_concentratetime")= timeStart
					rs("raid_actiontime")= timeStart
					rs("raid_endtime")= timeEnd
					rs("raid_personnel")=40
					rs("raid_player")=""
					rs("raid_commander")= request("raid_commander")
					rs("raid_plan")= htmlencode2(request("raid_plan"))
					if rs("raid_step")=0 then
					rs("raid_step")=1
					rs("raid_ruler")=1
					rs("raid_ruler")=""
					end if
					if request("class_name")<>"" then rs("raid_class")=request("class_name")
					if request("ruler_name")<>"" then rs("raid_ruler")=request("ruler_name")
					rs.update
			'	response.write "添加新记录"
			else
					rs("raid_name")=strRaidTitle&strRaidnote
					If strRaidTitle&strRaidnote ="" And rs("raid_name")="" Then rs("raid_name")="未命名的活动"
					rs("raid_concentratetime")=timeStart
					rs("raid_actiontime")=timeStart
					rs("raid_endtime")=timeEnd
					if rs("raid_step")=0 then
					rs("raid_step")=1
					end if
					rs("raid_ruler")=1
					if request("class_name")<>"" then rs("raid_class")=request("class_name")
					if request("ruler_name")<>"" then rs("raid_ruler")=request("ruler_name")
					rs.update
			'	response.write "修改存在记录"
			end if
			rs.close
			RaidID = getRaidID(timeStart)
			'删除此Raid全部事件
			conn.execute ("Delete * from raid_event where event_raidid="&RaidID)
		End Sub

		'成员创建/更新
		Sub dbRenewPlayers(arrPlayer)
			strPlayerList = ","
			For pindex = 0 To UBound(arrPlayer)-1
				strPlayerList = strPlayerList&arrPlayer(pindex,0)&","
				sql="select * from player where player_name='"&arrPlayer(pindex,0)&"'"
				rs.open sql,conn,1,3
					if rs.eof or rs.bof then
						rs.close
						sql="select * from player where (id is null)"
						rs.open sql,conn,1,3
						rs.addnew
							rs("player_name")=arrPlayer(pindex,0)
							rs("player_level")=arrPlayer(pindex,6)
							rs("player_tribe")=getFormatRaceName(arrPlayer(pindex,1))
							rs("player_profession")=getFormatProfessionName(arrPlayer(pindex,4))
							'rs("player_guildlevel")=strGuildRank
							'rs("player_honor")="无"
							rs("player_jointime")= timestart
							rs("player_BaseDKP")=0
							rs("player_DKP")=0
							rs("player_skill_1")="未知"
							rs("player_skill_2")="未知"
							rs("player_looted")=""
						rs.update
					else
						if rs("player_level")<>strLevel or rs("player_tribe")<>getFormatRaceName(strRace) or rs("player_profession")<>getFormatProfessionName(strClass) then
							rs("player_name")=arrPlayer(pindex,0)
							rs("player_tribe")=getFormatRaceName(arrPlayer(pindex,1))
							if strGuildRank<>"" then rs("player_guildlevel")=strGuildRank
							rs("player_profession")=getFormatProfessionName(arrPlayer(pindex,4))				
							rs.update
						elseif rs("player_guildlevel")<>strGuildRank and strGuildRank<>"" then
							rs("player_guildlevel")=strGuildRank
							rs.update
						end if
					end if
				rs.close
			Next
		End Sub

		'在Raid中写入参与人员ID
		Sub dbAddRaidPlayer(strPlayerList)
			sql = "select * from raid where id="&RaidID
			rs2.open sql,conn,1,3
			rs2("raid_player")=getPlayerIDs(strPlayerList)
			rs2.update
			rs2.close
		End Sub

		'加入事件处理
		Sub processJoinEvents(ArrJoin)
			If Not IsArray(Arrjoin) Then Exit Sub
			Response.write "处理成员加入事件...<br>"
			Sql="Select * from raid_event where (id is null)"
			rs2.open sql,conn,1,3
			for Jindex = 0 to UBound(ArrJoin)-1
				If ArrJoin(Jindex,0) <> "" Then
					if DateDiff("n", ArrJoin(Jindex,1), timeStart)<0 then
						rs2.addnew
						rs2("event_raidid")=RaidID
						rs2("event_time")=ArrJoin(Jindex,1)
						rs2("event_class")="加入"
						rs2("event_dkp")=0
						rs2("event_object")=name2idS(ArrJoin(Jindex,0))
						rs2("event_object2")=""
						rs2.update
					end If
				End If
			next
			rs2.close
			Response.write "完成<br>"
		End Sub

		'离开相关处理
		Sub processLeaveEvents(ArrLeave) 
			If Not IsArray(ArrLeave) Then Exit Sub
			Response.write "处理成员离开事件...<br>"
			Sql="Select * from raid_event where (id is null)"
			rs2.open sql,conn,1,3
			for Lindex = 0 to UBound(ArrLeave)-1
				If ArrLeave(Lindex,0) <> "" Then
					if DateDiff("n",ArrLeave(Lindex,1),timeEnd) > 5 then
						rs2.addnew
						rs2("event_raidid")=RaidID
						rs2("event_time")=ArrLeave(Lindex,1)
						rs2("event_class")="离开"
						rs2("event_dkp")=0
						rs2("event_object")=name2idS(ArrLeave(Lindex,0))
						rs2("event_object2")=""
						rs2.update
					end if
				end If
			next
			rs2.close
			Response.write "完成<br>"
		End Sub

		'首领击杀事件处理
		Sub processBosskillsEvents(ArrBosskill)
			If Not IsArray(ArrBosskill) Then Exit Sub
			Response.write "处理首领击杀事件..."
			Sql="Select * from raid_event where (id is null)"
			rs.open sql,conn,1,3
			for kindex = 0 to UBound(ArrBosskill)-1
				rs.addnew
				rs("event_raidid")=RaidID
				rs("event_time")=ArrBosskill(kindex,1)
				rs("event_class")="击杀"
				rs("event_dkp")="0"
				rs("event_object")="-"
				rs("event_object2")=ArrBosskill(kindex,0)
				rs.update
			next
			rs.close
			Response.write "完成<br>"
		End Sub

		'物品相关处理|||
		Sub processLootEvents(ArrLoot)	
			If Not IsArray(ArrLoot) Then Exit Sub
			Response.write "处理物品拾取事件...<br>"
			Sql="Select * from raid_event where (id is null)"
			rs.open sql,conn,1,3
				for Lindex = 0 to UBound(ArrLoot)-1
						itemName = ArrLoot(Lindex,0)
						itemID = ArrLoot(Lindex,1)
						itemIcon = ArrLoot(Lindex,2)
						itemColor = ArrLoot(Lindex,3)
						itemCount = ArrLoot(Lindex,4)
						itemLooter = ArrLoot(Lindex,5)
						itemCosts = ArrLoot(Lindex,6)
						If ArrLoot(Lindex,6) = "" Or Not IsNumeric(ArrLoot(Lindex,6)) Then itemCosts = 0
						itemLootTime = ArrLoot(Lindex,7)
						itemZone = ArrLoot(Lindex,8)
						itemWreck = ArrLoot(Lindex,9)
						itemTooltip = ArrLoot(Lindex,10)
						itemNote = ArrLoot(Lindex,11)
						itemPay = ""
						If itemNote <> "" Then 
							if Instr(itemNote,"/") then
								itemPay=Right(itemNote,len(itemNote)-instr(itemNote,"/"))
								itemCosts = Left(itemNote,instr(itemNote,"/")-1)
							Else
								itemCosts = itemNote
							end If
						End If

						If itemTooltip <> "" Then
							itemTooltip = itemColor&";"&itemIcon&";"&itemTooltip
						End If



						'Response.write itemName&" "&itemCosts&" {"&itemPay&"}<br>"
						for ci = 1 to Cint(itemCount)
							If IsNumeric(itemCosts) Then 
								Call dbADDRaidLoot("拾取", itemCosts , itemPay, name2idS(itemLooter), itemName&"#"&itemID, itemLootTime, itemTooltip)
							ElseIf UCase(itemNote)="BOE" Then
								Call dbADDRaidLoot("仓库",intBankItemCost,itemNote,name2idS(itemLooter),itemName&"#"&itemID, itemLootTime, itemTooltip)
							ElseIf UCase(itemNote)="ENC" Then
								Call dbADDRaidLoot("分解",0,0,name2idS(itemLooter),itemName&"#"&itemID, itemLootTime, itemTooltip)
							End If
						next
				next
			rs.close
			Response.write "完成<br>"
		End Sub

		'获得db的指定活动开始时间的条目ID
		Function getRaidID(t)
			sql = "select id from raid where raid_concentratetime=#"&t&"#"
			rs.open sql,conn,1,1
			getRaidID=rs("id")
			rs.close
		End Function

		'获得一组角色名字的ID数组
		Function getPlayerIDs(strPlayerList)
			strPlayerList = Split(Mid(left(strPlayerList,len(strPlayerList)-1),2),",")
			ReDim arrPlayerListNum(UBound(strPlayerList))
			sql="select * from player"
			rs3.open sql,conn,1,1
			for i = 1 to rs3.recordcount
				for j = 0 to UBound(strPlayerList)
					if rs3("player_name")=strPlayerList(j) then
					arrPlayerListNum(j)=rs3("id")
					end if
				next
				rs3.movenext
			next
			rs3.close
			getPlayerIDs=join(arrPlayerListNum,", ")
		End Function

		'数据写入物品拾取事件
		Private Sub dbADDRaidLoot(strclass, cost1, cost2, O1, O2, itemLootTime, strtooltip)
			rs.addnew
			rs("event_raidid")=RaidID
			rs("event_time")=itemLootTime
			rs("event_class")= strclass
			rs("event_dkp")= cost1
			rs("event_object")=O1
			rs("event_object2")=O2
			rs("event_object2_tooltip")=""
			if cost2<>"" then rs("event_dkp2")=cost2
			if strtooltip<>"" then rs("event_object2_tooltip")= strtooltip
			rs.update
		End Sub

		'滤掉多余的加入离开事件(由插件重复记录引起)
		Sub fixEvents(events)
			If Not IsArray(events) Then Exit Sub
			For eventindex = 0 To UBound(events)-1
				If events(eventindex,0) <> "" then
					For subindex = eventindex+1 To UBound(events)-1
						If events(subindex,0) <> "" Then
							If events(eventindex,0) = events(subindex,0) And DateDiff("n",events(eventindex,1),events(subindex,1)) < 5 Then
								events(subindex,0) = ""
								events(subindex,1) = ""
							End If 
						End If 
					Next 
				End If
			Next
		End Sub

		'滤掉暂时的离线事件: 同一角色在离线事件后的5分钟内如果发现有加入事件则删除这对事件.
		Sub fixOfflineEvents(joinevents,leaveevents)
			If Not (IsArray(joinevents) And IsArray(leaveevents)) Then Exit Sub
			For jindex = 0 To UBound(joinevents)-1
				If joinevents(jindex,0) <> "" Then
					For lindex = 0 To UBound(leaveevents)-1
						If leaveevents(lindex,0) <> "" And joinevents(jindex,0) <> "" Then
							If joinevents(jindex,0) = leaveevents(lindex,0) Then
								If ( DateDiff("n",joinevents(jindex,1),leaveevents(lindex,1)) > -5 And DateDiff("n",joinevents(jindex,1),leaveevents(lindex,1)) < 0 )  Then 
								'Or (DateDiff("n",joinevents(jindex,1),leaveevents(lindex,1)) < 5 And DateDiff("n",joinevents(jindex,1),leaveevents(lindex,1)) > 0)
									Response.write joinevents(jindex,0)&" 离线修正,删除值对: 加入"&joinevents(jindex,1) &" , 离开"& leaveevents(lindex,1)&" , "&DateDiff("n",joinevents(jindex,1),leaveevents(lindex,1))&"<br>"
									joinevents(jindex,0) = ""
									joinevents(jindex,1) = ""
									leaveevents(lindex,0) = ""
									leaveevents(lindex,1) = ""
								End If
							End If 
						End If 
					Next 
				End If
			Next
		End Sub



	Case "Post" '处理提交信息

		'变量声明
		Dim DataFormat
		Dim raidTime , raidNote
		Dim playerName , playerRace , playerClass , playerLevel , playerJoinTime
		Dim leavePlayerName , leavePlayerTime
		Dim itemName , itemID , itemColor , itemIcon , itemCount , itemLooter , itemLootTime , itemNote , itemCosts
		Dim ChildrenCount
		Dim arrPlayerList , arrLeavePlayerList , arrLeavePlayerTime
		Dim RaidEndTime
		Dim chkerror

		DataFormat=Request.form("xmlversion")
		'有表单数据就覆盖旧缓存文件
		if not (request.form("xmltext")="") Then
			Call saveXMLFile("Import.xml",request.form("xmltext"))
		end if

		'建立DOM对象
		Set rXML = server.CreateObject("Msxml2.DOMDocument.3.0") 
		rXML.load server.MapPath("xml/Import.xml") 
		Set rtXML=rXML.documentelement 

		'建立DOM对象B
		Set sXML = server.CreateObject("Msxml2.DOMDocument.3.0") 
		sXML.load server.MapPath("xml/Import.xml") 
		Set stXML=sXML.documentelement 
		
		'检查数据有效性
		chkerror=0

		Call checkXMLValidity()

		if chkerror>0 then
			Response.write "<h3>数据不完整,程序停止分析</h3>"&errtext
		else
			Set playerXML=rXML.getElementsByTagName("joins")(0).childNodes
			'playerXML.length
			Set leaveplayerXML=rXML.getElementsByTagName("leaves")(0).childNodes
			Set LootXML=rXML.getElementsByTagName("loots")(0).childNodes
			Set playerXMLs=sXML.getElementsByTagName("joins")(0).childNodes
			Set playerinfosXML=rXML.getElementsByTagName("playerinfos")(0).childNodes
			'执行分析程序
			Call ImportPost()
			Response.write "<h3>数据已完成导入,<a href='admin_report.asp'>查看活动列表</a></h3>"
		end if
	Case Else
		Call ImportMenu()
End Select
%>

  </div>
<div id="footer"><!--#include file="footer.asp"--></div>
</body>
</html>


<%
Sub ImportPost()

			Call processPlayer_RT150()
			Call processJoinEvents_RT150()
			Call processLeaveEvents_RT150()
			Call CTRT_Loot10()
			Call processBosskillsEvents_RT150()

'		if DataFormat="MRT207" then
'			Call processPlayer_RT150()
'			Call processJoinEvents_RT150()
'			Call processLeaveEvents_RT150()
'			Call CTRT_Wipes()
'			Call CTRT_Loot10()
'			Call processBosskillsEvents_RT150()
'		end if
		
End Sub


Sub ImportMenu()
	Response.write "<a href='?Action=Form'>数据导入</a>"
	Response.write " | <a href='?Action=Post'>查看分析结果</a>"
End Sub

Sub ImportForm()
Response.write "<form method='post' action='?Action=RexPost'><table class='outframe interlace'>"
Response.write "<tr><th colspan='2'><div class='title'><img src='images/icon/armorkit.jpg'>数据导入 - 通过导入记录插件的数据来建立活动 </div><div class='filter'><a href='admin_raid.asp?action=newplan' class='abtn3'>采用手工方式建立</a></div></th></tr>"
Response.write "<tr><td width='150px'>DKP分类</td><td> "&formselect("raid_class","id","class_name"," ")&" 辅助规则 "&formselect("ruler","id","ruler_name"," ")&"</td></tr>"
'Response.write "<tr><td>数据来源</td><td><select name='xmlversion'><option value='auto' selected>自动</option><option value='RT150'>CT_RaidTrack 1.5.0 (MLdkp输出格式)</option><option value='MRT207'>MerRT 2.0.7 (新CTRT字串)</option></select></td></tr>"
Response.write "<tr><td>字串 (必填)</td><td>复制来自活动记录插件的字串到这里<br><textarea name='xmltext' rows='15' style='width:90%;'></textarea></td></tr>"
Response.write "<tr><td></td><td><a href=""javascript:;"" name='expansion'>+ 填写详细信息</a></td></tr>"
Response.write "<tr class='expansion'><td>活动标题</td><td><input name='raid_title' value='' size='40' /></td></tr>"
Response.write "<tr class='expansion'><td>指挥人</td><td><input name='raid_commander' value='' size='20' /></td></tr>"
Response.write "<tr class='expansion'><td>活动备注</td><td><textarea type='text' name='raid_plan' style='width:300px;height:50px;' ></textarea></td></tr>"
Response.write "<tr><td></td><td><input type='submit' value='提交处理' /></td></tr>"
Response.write "</table></form>"

%>
<table class='AddonTable interlace outframe'>
<tr>
	<th>支持活动记录插件</th>
</tr>
<tr><td>CT-RaidTracker</td></tr>
<tr><td>MerRT</td></tr>
<tr><td>ShowDKP</td></tr>
</table>
<%
End Sub

%>



